<?php

class Module {
  
  public static function getScriptNameFromModuleName($moduleName) {
    return "./mod/mod_$moduleName.php";
  }
  public static function getScriptNameForError() {
    return self::getScriptNameFromModuleName("error");
  }
  
  public static function loadModule($moduleName="default") {
    $scriptName = Module::getScriptNameFromModuleName($moduleName);
    if (file_exists($scriptName)) {
      
    } else {
      $errorMessage= "Module, $moduleName not found";
      $scriptName = self::getScriptNameForError();
      
    }
    require_once($scriptName);
  }
  
  public static function viewSource($moduleName="default") {
    $scriptName = Module::getScriptNameFromModuleName($moduleName);
    if (file_exists($scriptName)) {
      echo "<code>SORGENTE:<br>";
      //echo "<pre>";
      echo highlight_string(file_get_contents($scriptName));
      //echo"</pre>";
      echo "</code>";
    } else {
      echo "Non riesco a leggere il sorgente di $scriptName";
    }
    
  }
}
?>
